var LRUCache = function(maxCount) {
    this.maxCount = maxCount;
    this.map = new Map();
};

LRUCache.prototype.get = function(key) {
    if(this.map.has(key)){
        // 先用临时变量获取保存下来
        let temp = this.map.get(key)
        // 把值删除
        this.map.delete(key);
        // 再次保存
        this.map.set(key, temp);
        // 返回最访问值
        return temp
    }else{
        // 没有返回-1
        return -1
    }
};

LRUCache.prototype.put = function(key, value) {
    if(this.map.has(key)){
        this.map.delete(key);
    }
    this.map.set(key,value);
    if(this.map.size > this.maxCount){
        // 最近未访问的值就是：this.map.keys().next().value
        this.map.delete(this.map.keys().next().value);
    }
};
let p = new LRUCache(2)
console.log(p.put(1,1))
console.log(p.put(2,2))
console.log(p.get(1));
console.log(p.put(3,3))
console.log(p.get(2));
console.log(p.put(4,4))
console.log(p.get(1));
console.log(p.get(3));
console.log(p.get(4));

// output: undefined undefined 1 undefined -1 undefined -1 3 4